/*
  Copyright 1996-2003
  Simon Whiteside

*/
package simkin.examples.array;
import simkin.XMLExecutable;
import simkin.Interpreter;
import simkin.ExecutableContext;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;
import org.xml.sax.SAXException;

/**
 * This class shows how an array can be accessed by a Simkin script, where the array is stored in an XML file, or as a Java array
 */
public class ArrayExample extends XMLExecutable {
    /** this java array is public, and therefore accessible to the Simkin scripts */
    public String[] nativeArray={"Native Frodo","Native Bilbo","Native Gandalf"};
    /** constructor just passes the XML input stream to its parent */
    public ArrayExample(String location,InputStream in) throws SAXException,IOException{
	super(location,in);
    }
    /** load up the xml file named in the command line into an ArrayExample object and then run the main method */
    static public void main(String args[]){
	if (args.length>0){
	    try{
		// Create an interpreter and a context
		Interpreter interp=new Interpreter();
		ExecutableContext ctxt=new ExecutableContext(interp);

		// create an ArrayExample  object with the loaded script
		ArrayExample example=new ArrayExample(args[0],new FileInputStream(args[0]));

		// call the "main" method
		example.method("main",null,ctxt);

	    }catch(Exception e){
		e.printStackTrace();
	    }
	}
    }
}
